import java.util.*;


public class Solution {
    /**
     * 代码中的类名、方法名、参数名已经指定，请勿修改，直接返回方法规定的值即可
     *
     * 
     * @param numbers int整型一维数组 
     * @return int整型
     */
    public void swap(int[] nums,int left,int right) {
        int temp = nums[left];
        nums[left] = nums[right];
        nums[right] = temp;
    }

    public int duplicate (int[] numbers) {
        // write code here

        /*
        Arrays.sort(numbers);
        for (int i = 0; i < numbers.length - 1; i++) {
            if (numbers[i] == numbers[i + 1]) {
                return numbers[i];
            }
        }
        return -1;
        */

        /*
        int[] arr = new int[numbers.length];
        Arrays.fill(arr, 0);
        for (int i: numbers) {
            if (arr[i] > 0) {
                return i;
            }
            else {
                arr[i]++;
            }
        }
        return -1;
        */

        /*
        boolean[] t=new boolean[numbers.length];
        for(int i=0;i<numbers.length;i++){
            if(t[numbers[i]]){
                return numbers[i];
            }else{
                t[numbers[i]]=true;
            }
        }
        return -1;
        */

        int i = 0;
        while(i < numbers.length){
            if(numbers[i] == i){
                i++;
            }else {
                if(numbers[i] == numbers[numbers[i]]){
                    return numbers[i];
                }else{
                    swap(numbers,i,numbers[i]);
                }
            }
        }
        return -1;
    }
}